set more off

eststo clear

foreach dataset in sccbs gss ssi {

	use `dataset', clear

	local control income male married family_size age hs coll grad white black i.region

	su attend
	replace attend = (attend - r(min)) / (r(max)-r(min))

	if "`dataset'" == "sccbs" {
		gen conservativeXattend = conservative*attend
		gen moderateXattend = moderate*attend
		xi: eststo: reg ln_totgiv conservative moderate attend `control' 
		xi: eststo: reg ln_totgiv conservative conservativeXattend moderate moderateXattend attend `control' 
		
	}

	if "`dataset'" != "sccbs" {
		replace conservative = republican
		replace moderate = independent
		replace liberal = democrat
		gen conservativeXattend = conservative*attend
		gen moderateXattend = moderate*attend
		eststo: reg ln_totgiv conservative moderate attend `control' 
		eststo: reg ln_totgiv conservative conservativeXattend moderate moderateXattend attend `control' 
	}


}

label variable conservative "Conservative/Republican"
label variable conservativeXattend "Con/Rep X Attend"
label variable moderate "Moderate/Independent"
label variable moderateXattend "Mod/Ind X Attend"

#delimit;

esttab
	using "table2.tex"
	,
 		order(
			attend
			conservative 
			moderate
			conservativeXattend 
			moderateXattend
		)
		replace
 		gap
		compress
		stats(N r2, fmt(%20.00fc %20.02fc) label("Sample size" "R-squared"))
		booktabs
		cells(b(fmt(2) star) se(par))
		label
 		drop(*region*)
		collabels(none)
		width(\textwidth)
		mgroups(
			"SCCBS" "GSS" "SSI"
			,
				pattern(1 0 1 0 1 0)
				prefix(\multicolumn{@span}{c}{) suffix(})
				span erepeat(\cmidrule(lr){@span})
		)			nomtitles
		;

#delimit cr
